package com.wn;

import com.wn.dao.SensitiveWordDao;
import com.wn.entity.SensitiveWord;
import com.wn.utils.sysmgr.SensitiveWordInit;
import com.wn.utils.sysmgr.SensitivewordEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Component
public class StartService implements ApplicationRunner {

    @Autowired
    private SensitiveWordDao sensitiveWordDao;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 初始化敏感词库对象
        SensitiveWordInit sensitiveWordInit = new SensitiveWordInit();
        // 从数据库中获取敏感词对象集合（调用的方法来自Dao层，此方法是service层的实现类）
        List<SensitiveWord> sensitiveWords = sensitiveWordDao.getSensitiveWordListAll();
        // 构建敏感词库
        Map sensitiveWordMap = sensitiveWordInit.initKeyWord(sensitiveWords);
        // 传入SensitivewordEngine类中的敏感词库
        SensitivewordEngine.sensitiveWordMap = sensitiveWordMap;
    }
}
